//
//  DLCircleListSectionHeaderView.m
//  FRP_OC
//
//  Created by DeLongYang on 2017/11/3.
//  Copyright © 2017年 DeLongYang. All rights reserved.
//

#import "DLCircleListSectionHeaderView.h"
#import "DLCircleListSectionHeaderViewModel.h"

@interface DLCircleListSectionHeaderView ()

@property (nonatomic,strong) UIImageView *bgImageView;

@property (nonatomic,strong) UILabel *titleLabel;

@property (nonatomic,strong) UIImageView *lineImageView;

@property (nonatomic,strong) DLCircleListSectionHeaderViewModel *viewModel;

@end

@implementation DLCircleListSectionHeaderView

#pragma mark ---- DLViewProtocol
- (instancetype)initWithViewModel:(id<DLViewModelProtocol>)viewModel {
    
    self.viewModel = (DLCircleListSectionHeaderViewModel *)viewModel;
    return [super initWithViewModel:viewModel];
}

- (void)dl_setupViews {
    
    [self addSubview:self.bgImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.lineImageView];
    
    [self setNeedsUpdateConstraints];
    [self updateConstraints];
}

- (void)dl_bindViewModel
{
    // 发生明显改变的时候 更改 titleLabel 的text
    RAC(self.titleLabel,text) = [[RACObserve(self, viewModel.title) distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
}



#pragma mark ----  System UpdateConstraits
- (void)updateConstraints {
    
    WS(weakSelf)
    CGFloat paddingEdge = 10;
    
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(weakSelf);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(weakSelf);
        make.left.equalTo(@(paddingEdge));
        make.right.equalTo(@(-paddingEdge));
        make.height.equalTo(@20);
    }];
    
    [self.lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(weakSelf);
        make.height.equalTo(@1.0);
    }];
    
    [super updateConstraints];
}

#pragma mark ---- Lazy Load Getter
- (UIImageView *)bgImageView
{
    if (!_bgImageView) {
        
        _bgImageView = [[UIImageView alloc] init];
        _bgImageView.backgroundColor = white_color;
    }
    
    return _bgImageView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = SYSTEMFONT(17);
        _titleLabel.textColor = MAIN_BLACK_TEXT_COLOR;
    }
    
    return _titleLabel;
}

- (UIImageView *)lineImageView
{
    if (!_lineImageView) {
        
        _lineImageView = [[UIImageView alloc] init];
        _lineImageView.backgroundColor = MAIN_LINE_COLOR;
    }
    
    return _lineImageView;
}




























































































@end
